package com.example.homeworkmutualevaluation.Service;

import com.example.homeworkmutualevaluation.Dao.MessageDao;
import com.example.homeworkmutualevaluation.Entity.Message;
import com.example.homeworkmutualevaluation.Mapper.MessageMapper;
import com.example.homeworkmutualevaluation.utils.UniqueId;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageService {
    @Resource
    private MessageDao messageDao;
    @Resource
    private MessageMapper messageMapper;

    public boolean sendMsg(String tphone, String sphone, String title, String content) {
        return messageDao.insert(UniqueId.next(), tphone, sphone, title, content) > 0;
    }

    public int sendMsg(String tphone, List<String> sphoneList, String title, String content) {
        List<Message> messages = sphoneList.stream().map(sphone -> new Message(tphone, sphone, title, content)).toList();
        return messageMapper.insertBatchByNative(messages);
    }

    public boolean onRead(String id) {
        return messageDao.onRead(id) > 0;
    }

    public List<Message> getAllMsg(String sphone) {
        return messageDao.getAllMsg(sphone);
    }
}
